home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 4 / MacFormat n. 4 (Spain) / MacFormat 4.bin / La ciudad del ShareWare / HyperCard / Pictoids 2.0 / Pictoid Demo ƒ / WDEF Globals.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-28  |  1.4 KB  |  70 lines

  1. #include <GestaltEqu.h>
  2. #include "Pictoid.h"
  3.  
  4. #define mySIG '©NP2'
  5.  
  6. OSErr GetWDEFGlobals(Boolean create, WDEFGlobalsHand result)
  7. {    register WDEFGlobalsPtr work;
  8.     register long fSize;
  9.     static Rect maxR = { 0x8000, 0x8000, 0x7fff, 0x7fff };
  10.     
  11.     asm
  12.     {    
  13.     @start
  14.         move.l    #mySIG,d0
  15.         _Gestalt
  16.         ; OSErr in d0
  17.         bne.s    @notThere
  18.         move.l    a0,work
  19.         bra        @eachTime
  20.     @notThere
  21.         tst.b    create
  22.         beq        @exit
  23.         ; create the globals
  24.         lea        @funcEnd,work
  25.         lea        @funcBeg,a0
  26.         suba.l    a0,work            ; size of gestalt function
  27.         move.l    work,d0
  28.         move.l    d0,fSize        ; save size
  29.         add.l        #sizeof(WDEFGlobals),d0    ; add in global space
  30.         _NewPtr    CLEAR+SYS
  31.         bne        @exit            ; couldn't get memory
  32.         move.l    a0,a1
  33.         lea        @funcBeg,a0
  34.         move.l    work,d0
  35.         move.l    a1,work            ; save destination
  36.         _BlockMove                ; copy function
  37.         move.l    #mySIG,d0
  38.         move.l    work,a0
  39.         _NewGestalt        ; allocate
  40.         add.l        fSize,work    ; get past code
  41.     eachTime:
  42.         }
  43.             *result = work;
  44.             return noErr;
  45.         asm {
  46.         ; failed, return memory
  47.         move.l    work,a0
  48.         move.w    d0,work            ; save reason for fail
  49.         _DisposPtr
  50.         move.w    work,d0            ; restore error
  51.     @exit
  52.     }
  53.     
  54.     return;
  55.     
  56.     /* the gestalt function: pascal OSErr funcBeg(OSType, long *) */
  57.     asm
  58.     {
  59.     @funcBeg:
  60.         movem.l    (a7)+,d0/a0/a1    ; d0 = return address, a0 = long *, a1 = selector
  61.         clr.w        (a7)                ; return noErr        
  62.         lea        @globals,a1
  63.         exg        a1,d0                ; ans -> d0, ret addr -> a1
  64.         move.l    d0,(a0)
  65.         jmp        (a1)
  66.     @funcEnd:
  67.     @globals:
  68.         ; struct WDEFGlobals added here
  69.     }
  70. }